import {payMoney} from '../../api/pay.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    payOrderId: '',
    payPrice: '0.00',
    payWay: 'wechat',
    payList: [{
        label: '微信支付',
        value: 'wechat'
      },
      {
        label: '余额支付',
        value: 'wallet'
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { id, payOrderId, payPrice } = options
    this.setData({
      id,
      payOrderId,
      payPrice
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  radioChange(e) {
    this.setData({
      payWay: e.detail.value
    })
  },
  async goPay(){
    const data = this.data
    const params = {
      id: data.payOrderId,
      channelCode: data.payWay
    }
    const res = await payMoney(params)
    if (res) {
      wx.reLaunch({
        url: `/pages/payResult/index?status=${res.status}`
      })
    }
  }
})